<%@ Page Language="C#" %>
<script type="text/C#" runat="server">
    private const string NoPic = "/Images/no_pic.gif";
    private void Page_Load(object sender, System.EventArgs e)
    {
        if (Page.User.Identity.Name == "")
        {
            Response.End();
        }
    }

    protected string GetNickName()
    {
    	string tmp = "";
        using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["www_user.user"].ConnectionString))
        {
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("select NickName from t_user where memberno='" + Page.User.Identity.Name + "'", conn);
            conn.Open();
            System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                tmp = dr[0].ToString();
                break;
            }
            dr.Close();
            conn.Close();
        }
        return tmp;
    }

    protected string GetAvatar()
    {
    	string Avatar = NoPic;
        using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["www_user.user"].ConnectionString))
        {
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("select Avatar from t_user where memberno='" + Page.User.Identity.Name + "'", conn);
            conn.Open();
            System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                Avatar = dr[0].ToString();
                Avatar = (Avatar.Trim() == "" ? NoPic : Avatar);
                break;
            }
            dr.Close();
            conn.Close();
        }
        return Avatar;
    }
</script>

<%
	// You need to set these variables to be appropriate for your site and user.  Some will be provided by Userplane during account setup
	// If you have not received these values yet please contact Userplane at support@userplane.com or call (323) 938-4401
	String strFlashcomServer = "flashcom.italki.userplane.com";	// The flashcom server: flashcom.yourcompany.userplane.com (from Userplane)
	String strDomainID = "italki.com";								// The domain ID of this site: yourdomain.com (from Userplane)
    String strSessionGUID = Page.User.Identity.Name;									// The session identifier for the currently logged in user
    String strKey = GetNickName();												// Additional login information you may need passed
	
	// You will need to work on the sendCommand JavaScript function a few lines down to respond to any user clicks as you deem necessary
	
	String strDestinationUserID = Request.QueryString["strDestinationUserID"];
%>

<html>
<head>
	<meta http-equiv=Content-Type content="text/html;  charset=ISO-8859-1">
	<title>Userplane AV Webmessenger</title>

	<script language="JavaScript">
	<!--
		function sendCommand( commandIn, valueIn )
		{
			if( commandIn == "focus" )
			{
				// DO NOT EDIT
			
				var wmObject = getWMObject();
				// only do the focus if we are sure it is not going remove focus from typing area
				if( wmObject != null && ( wmObject.focus != undefined || ( navigator.userAgent.indexOf( "MSIE" ) >= 0 && navigator.userAgent.indexOf( "Mac" ) >= 0 ) ) )
				{
					window.focus();
					wmObject.focus();
				}
			}
			else
			{
				// EDIT HERE: you will need to handle the following commands from the wm client
				if( commandIn == "viewProfile" )
				{
					if( valueIn == "-1" )
					{
						// view their own profile
						window.open("/public/Profile.htm");
					}
					else
					{
						var userID = valueIn;
						// view userID's profile
				        var tmp = "T";
				        for(var i=0;i<9-userID.length;i++)
				        {
				            tmp +="0";
				        }
				        userID = tmp + userID;
				        window.open("/public/Profile.htm?memberno="+userID);
					}
				}
				else if( commandIn == "help" )
				{
					// view the help
				}
				else if( commandIn == "buddyList" )
				{
					// view their buddy list
					var userID = valueIn;
					 var tmp = "T";
				   for(var i=0;i<9-userID.length;i++)
				   {
				      tmp +="0";
				   }
				   userID = tmp + userID;
				   window.open("/contacts/mycontacts.htm?memberno="+userID);
				}
				else if( commandIn == "preferences" )
				{
					// view the preferences
				}
				else if( commandIn == "addBuddy" )
				{
					 var userID = valueIn;
					 var tmp = "T";
				   for(var i=0;i<9-userID.length;i++)
				   {
				      tmp +="0";
				   }
				   userID = tmp + userID;
				   window.open("/contacts/inviteconfirm.htm?memberno="+userID);
				}
				else if( commandIn == "block" )
				{
					// they blocked the user
				}
				else if( commandIn == "unblock" )
				{
					// they unblocked the user
				}
				else if( commandIn == "Connection.Success" )
				{
					// client successfully connected to server
				}
				else if( commandIn == "Connection.Failure" )
				{
					// client was disconnected from server
				}
				else if( commandIn == "Game.Open" ) 
				{ 
					openGameWindow( valueIn ); 
				} 		
			}
		}
		
		function focusIt()
		{
			window.focus();
		
			var wmObject = getWMObject();
			
			if( wmObject != null && wmObject.focus != undefined )
			{
				wmObject.focus();
			}
		}
		
		function getWMObject()
		{
			if(document.all)
			{
				return document.all["wm"];
			}
			else if(document.layers)
			{
				return document.wm;
			}
			else if(document.getElementById)
			{
				return document.getElementById("wm");
			}
			
			return null;
		}
		
		function wm_DoFSCommand( command, args ) 
		{
		}
		function openGameWindow( qs ) 
		{ 
			var newWindow = window.open("http://www.userplane.com/chatlite/games/?" + qs,"game","width=600,height=555,scrollbars=yes,resizable=yes,menubar=yes,location=no,status=no,directories=no,toolbar=no"); 

			if (newWindow == null) 
			{ 
				alert( "Your popup blocker stopped the game window from opening" ); 
			} 
		} 
	//-->
	</script>
	
	<script language="VBScript">
	<!-- 
		//  Map VB script events to the JavaScript method - Netscape will ignore this... 
		//  Since FSCommand fires a VB event under ActiveX, we respond here 
		Sub wm_FSCommand(ByVal command, ByVal args)
	  		call wm_DoFSCommand(command, args)
		end sub
	-->
	</script>
</head>
<body onLoad="javascript: focusIt();" bgcolor="#ffffff" bottommargin="0" leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" topmargin="0">

	<%
		if( strDestinationUserID != null )
		{
			String strSwfServer = "swf.userplane.com";
			String strApplicationName = "Webmessenger";
			String strLocale = "english";
			%>
		
			<script type="text/javascript" src="flashobject.js"></script>
			
			<!--- 
				The content of this div should hold whatever HTML you would like to show in the case that the 
				user does not have Flash installed.  Its contents get replaced with the Flash movie for everyone
				else.
			--->
			<div id="flashcontent">
				<strong>You need to upgrade your Flash Player by clicking <a href="http://www.macromedia.com/go/getflash/" target="_blank">this link</a>.</strong><br><br><strong>If you see this and have already upgraded we suggest you follow <a href="http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_14157" target="_blank">this link</a> to uninstall Flash and reinstall again.</strong>
			</div>
			
			<script type="text/javascript">
				// <![CDATA[
				
				var fo = new FlashObject("http://<%= strSwfServer %>/<%= strApplicationName %>/ic.swf", "wm", "100%", "100%", "6", "#ffffff", false, "best");
				fo.addParam("scale", "noscale");
				fo.addParam("menu", "false");
				fo.addParam("salign", "LT");
				fo.addParam("allowScriptAccess", "always");
				fo.addVariable("server", "<%= strFlashcomServer %>");
				fo.addVariable("swfServer", "<%= strSwfServer %>");
				fo.addVariable("applicationName", "<%= strApplicationName %>");
				fo.addVariable("domainID", "<%= strDomainID %>");
				fo.addVariable("sessionGUID", "<%= strSessionGUID %>");
				fo.addVariable("key", "<%= strKey %>");
				fo.addVariable("locale", "<%= strLocale %>");
				fo.addVariable("destinationMemberID", "<%= strDestinationUserID %>");
				fo.addVariable("resizable", "true");
				fo.write("flashcontent");
				
				// COPYRIGHT Userplane 2006 (http://www.userplane.com)
				// WM version 1.8.13
				
				// ]]>
			</script>
			
			<%
		}
	%>
</body>
</html>
